home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 August / August CD.bin / Shareware / Programming / SpriteWorld / Examples / Simple / Application.c < prev    next >
C/C++ Source or Header  |  1993-06-06  |  3KB  |  231 lines

  1. ///--------------------------------------------------------------------------------------
  2. //    Application.c
  3. //
  4. //    Created:    Sunday, April 11, 1993
  5. //    By:        Tony Myles
  6. //
  7. //    Copyright: © 1993 Tony Myles, All rights reserved worldwide.
  8. ///--------------------------------------------------------------------------------------
  9.  
  10.  
  11. #if THINK_C
  12. #ifndef __BDC__
  13. #include <BDC.h>
  14. #endif
  15. #else
  16. #ifndef __PACKAGES__
  17. #include <Packages.h>
  18. #endif
  19. #endif
  20.  
  21. #ifndef __APPLEEVENTS__
  22. #include <AppleEvents.h>
  23. #endif
  24.  
  25. #ifndef __DESK__
  26. #include <Desk.h>
  27. #endif
  28.  
  29. #ifndef __DIALOGS__
  30. #include <Dialogs.h>
  31. #endif
  32.  
  33. #ifndef __DISKINIT__
  34. #include <DiskInit.h>
  35. #endif
  36.  
  37. #ifndef __EPPC__
  38. #include <EPPC.h>
  39. #endif
  40.  
  41. #ifndef __EVENTS__
  42. #include <Events.h>
  43. #endif
  44.  
  45. #ifndef __ERRORS__
  46. #include <Errors.h>
  47. #endif
  48.  
  49. #ifndef __FONTS__
  50. #include <Fonts.h>
  51. #endif
  52.  
  53. #ifndef __GESTALTEQU__
  54. #include <GestaltEqu.h>
  55. #endif
  56.  
  57. #ifndef __MENUS__
  58. #include <Menus.h>
  59. #endif
  60.  
  61. #ifndef __RESOURCES__
  62. #include <Resources.h>
  63. #endif
  64.  
  65. #ifndef __OSEVENTS__
  66. #include <OSEvents.h>
  67. #endif
  68.  
  69. #ifndef __TEXTEDIT__
  70. #include <TextEdit.h>
  71. #endif
  72.  
  73. #ifndef __TRAPS__
  74. #include <Traps.h>
  75. #endif
  76.  
  77. #ifndef __TOOLUTILS__
  78. #include <ToolUtils.h>
  79. #endif
  80.  
  81. #ifndef __WINDOWS__
  82. #include <Windows.h>
  83. #endif
  84.  
  85. #ifndef __SPRITEWORLDUTILS__
  86. #include <SpriteWorldUtils.h>
  87. #endif
  88.  
  89. #ifndef __APPLICATION__
  90. #include "Application.h"
  91. #endif
  92.  
  93. #include "Simple.h"
  94.  
  95.  
  96. WindowPtr gWindowP = NULL;
  97.  
  98.  
  99. void main(void)
  100. {
  101.     Initialize(kNumberOfMoreMastersCalls);
  102.  
  103.     if (CheckSystem())
  104.     {
  105.         CreateWindow();
  106.  
  107.         ShowWindow(gWindowP);
  108.  
  109.         PerformSimpleAnimation((CWindowPtr)gWindowP);
  110.  
  111.         DisposeWindow(gWindowP);
  112.     }
  113.     else
  114.     {
  115.         CantRunOnThisMachine();
  116.     }
  117.  
  118.     ExitToShell();
  119. }
  120.  
  121.  
  122. void Initialize(short numberOfMasters)
  123. {
  124.     EventRecord tempEvent;
  125.  
  126.     MaxApplZone();
  127.  
  128.     while (numberOfMasters--)
  129.     {
  130.         MoreMasters();
  131.     }
  132.  
  133.     InitGraf(&qd.thePort);
  134.     InitFonts();
  135.     InitWindows();
  136.     InitMenus();
  137.     TEInit();
  138.     InitDialogs(NULL);
  139.     InitCursor();
  140.     FlushEvents(everyEvent, 0);
  141.  
  142.     (void)EventAvail(everyEvent, &tempEvent);
  143.     (void)EventAvail(everyEvent, &tempEvent);
  144.     (void)EventAvail(everyEvent, &tempEvent);
  145. }
  146.  
  147.  
  148. Boolean CheckSystem(void)
  149. {
  150.     OSErr    err;
  151.     Boolean isSystemGood = true;
  152.     long    gestaltResult;
  153.  
  154.     err = Gestalt(gestaltTimeMgrVersion, &gestaltResult);
  155.  
  156.     isSystemGood = (err == noErr) && (gestaltResult >= gestaltStandardTimeMgr);
  157.  
  158.     if (!isSystemGood)
  159.     {
  160.         CantRunOnThisMachine();
  161.     }
  162.  
  163.     return isSystemGood;
  164. }
  165.  
  166.  
  167. void CreateWindow(void)
  168. {
  169.     gWindowP = SWHasColorQuickDraw() ?
  170.             GetNewCWindow(kWindowResID, NULL, (WindowPtr)-1L) :
  171.             GetNewWindow(kWindowResID, NULL, (WindowPtr)-1L);
  172.  
  173.     if (gWindowP == NULL)
  174.     {
  175.         CantFindResource();
  176.     }
  177. }
  178.  
  179.  
  180. void ErrorAlert(OSErr err, short errorStringIndex)
  181. {
  182.     Str255 messageString, errorString;
  183.  
  184.     GetIndString(messageString, kErrorStringListResID, errorStringIndex);
  185.  
  186.     if (messageString[0] == 0)
  187.     {
  188.         BlockMove(kSeriousDamageString, messageString, sizeof(kSeriousDamageString));
  189.     }
  190.  
  191.     NumToString(err, errorString);
  192.  
  193.     ParamText(messageString, errorString, "\p", "\p");
  194.  
  195.     (void)StopAlert(kErrorAlertResID, NULL);
  196. }
  197.  
  198.  
  199. void FatalError(OSErr err)
  200. {
  201.     if (err != noErr)
  202.     {
  203.         ErrorAlert(err, kFatalErrorStringIndex);
  204.  
  205.         ExitToShell();
  206.     }
  207. }
  208.  
  209.  
  210. void CantFindResource(void)
  211. {
  212.     OSErr err;
  213.  
  214.     err = ResError();
  215.  
  216.     if (err == noErr)
  217.     {
  218.         err = resNotFound;
  219.     }
  220.  
  221.     ErrorAlert(err, kCantFindResourceStringIndex);
  222.  
  223.     ExitToShell();
  224. }
  225.  
  226.  
  227. void CantRunOnThisMachine(void)
  228. {
  229.     (void)StopAlert(kCantRunAlertResID, NULL);
  230. }
  231.